<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MAS extends CI_Controller {
 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');
 }
 function index(){ 	
     $roles=$this->session->userdata('roles');
 	 $config['base_url'] = base_url().'MAS/index'; 
	 $config['total_rows'] = $this->muser->num_rows('MAS');
	 
	 $config['per_page'] = 10; // xác định số record ở mỗi trang  
     $config['uri_segment'] = 3; // xác định segment chứa page number  
	 $this->pagination->initialize($config); 
	 $data['result']=$this->muser->getalldata('MAS',$config['per_page'],$this->uri->segment(3));	
	
	 $data['staff']=$this->getStaffID();
	 $data['monthlyAllow']=$this->getMonthlyAllowID();
         if($roles==0||$roles==1)
         {
	 $this->load->view('_header');
     $this->load->view('MAS/MAS_view',$data); 
     $this->load->view('_footer');
         }
     else
         {
             $data['ban_roles']="You haven't this role";
             $this->load->view('_header',$data);
             $this->load->view('notAllowRole');
             $this->load->view('_footer');
         }
 }
	
function insert()
	{
			$DT['MAS_ID']=$this->input->post('MAS_ID');	
		 	$DT['Staff_ID']=$this->input->post('Staff_ID');
			$DT['MonthlyAllow_ID']=$this->input->post('MonthlyAllow_ID');
			$DT['ActiveDate']=$this->input->post('ActiveDate');
			$DT['EndDate']=$this->input->post('EndDate');
			$this->muser->addData('MAS',$DT);
			$data['error']='Insert successful!';
			redirect('MAS/index');
		
	}	
 function delete($MAS_ID){
 	$this->muser->delColumn('MAS','MAS_ID',$MAS_ID);
	redirect('MAS/index');
 }
 
 function edit1 ()
 {
 	$DT['MAS_ID']=$this->input->post('MAS_ID');	
	$DT['Staff_ID']=$this->input->post('Staff_ID');
	$DT['MonthlyAllow_ID']=$this->input->post('MonthlyAllow_ID');
	$DT['ActiveDate']=$this->input->post('ActiveDate');
	$DT['EndDate']=$this->input->post('EndDate');
	$this->muser->updateData('MAS','MAS_ID',$DT['MAS_ID'],$DT);
	$data['error']='Edit successful!';	 	
	redirect('MAS/index',$data);		
 } 
 function edit($str)
 {	
 	$result=$this->muser->getRdata('MAS','MAS_ID',$str);
	$data['result']=$result;
	$data['staff']=$this->getStaffID();
	$data['monthlyAllow']=$this->getMonthlyAllowID();	
 	$this->load->view('_header');
	$this->load->view('MAS/editMAS_view',$data);	
	$this->load->view('_footer');
 }
 
 function check_MAS($str){
 		return $this->muser->checkData('MAS','MAS_ID',$str);		
 }
 function getStaffID(){
 	 $lab1=$this->muser->getData('Staff');
	 foreach ($lab1 as $row) {
		 $lab[$row->Staff_ID]=$row->Staff_ID.'-'.$row->FullName;
	 }
	 return $lab;
 }
 function getMonthlyAllowID(){
 	 $lab1=$this->muser->getData('MonthlyAllow');
	 foreach ($lab1 as $row) {
		 $lab[$row->MonthlyAllow_ID]=$row->MonthlyAllow_ID.'-'.$row->Allowance;
	 }
	 return $lab;
 }
}